package main

import (
	"fmt"
	"github.com/influxdata/influxdb/client"
	"log"
	"net/url"

)

func main() {
	en()
}

// 获取influxdb 客户端
func en(ip string, port int, dbName string) {
	host, err := url.Parse(fmt.Sprintf("http://%s:%d", ip, port))
	if err != nil {
		log.Fatal(err)
	}

	conf := client.Config{
		URL:      *host,
		Username: "",
		Password: "",
	}

	con, err := client.NewClient(conf)
	if err != nil {
		log.Fatal(err)
	}

	log.Println("Connection", con)

	q := client.Query{
		Command: "SELECT * FROM cpu WHERE host='server01' AND time < now() - 1d",
		Database: dbName,
	}

	fmt.Println(q)
}
